<%@ page import="java.util.ArrayDeque" %>
<%--
  Created by IntelliJ IDEA.
  User: lzy
  Date: 18-8-2
  Time: 上午11:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>book list</title>
</head>
<body>
<h4 style="color: blue; font-weight: bold">Books page</h4>

<a href="book.jsp?book=JavaWeb">Java Web</a><br/>
<a href="book.jsp?book=Java">Java</a><br/>
<a href="book.jsp?book=Oracle">Oracle</a><br/>
<a href="book.jsp?book=Ajax">Ajax</a><br/>
<a href="book.jsp?book=JavaScript">JavaScript</a><br/>
<a href="book.jsp?book=Android">Android</a><br/>
<a href="book.jsp?book=Jbpm">Jbpm</a><br/>
<a href="book.jsp?book=Structs">Structs</a><br/>
<a href="book.jsp?book=Hibernate">Hibernate</a><br/>
<a href="book.jsp?book=Spring">Spring</a><br/>

<br/><br/>

<p style="color: coral;font-weight: bolder">Latest five books:</p>
<%
    Cookie[] cookies = request.getCookies();
    ArrayDeque<String> lastBrowseBooks = new ArrayDeque<>();
    if (cookies != null && cookies.length > 0) {
        for (Cookie cookie : cookies) {
            String name = cookie.getName();
            if (name.startsWith("lastbrowse_")) {
                String bookName = cookie.getValue();
                lastBrowseBooks.addFirst(bookName);
            }
        }
    }

    for (Object book : lastBrowseBooks) {
        out.print("<a href=\"book.jsp?book=" + book + "\">" + book + "</a><br/>");
    }
%>

</body>
</html>
